package com.common;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.collections.MapUtils;

/**
 * 映射操作工具类
 *
 * @author huangyong
 * @since 1.0
 */
public class MapUtil {

    /**
     * 判断 Map 是否非空
     */
    public static boolean isNotEmpty(Map<?, ?> map) {
        return MapUtils.isNotEmpty(map);
    }

    /**
     * 判断 Map 是否为空
     */
    public static boolean isEmpty(Map<?, ?> map) {
        return MapUtils.isEmpty(map);
    }

    /**
     * 转置 Map
     */
    public static <K, V> Map<V, K> invert(Map<K, V> source) {
        Map<V, K> target = null;
        if (isNotEmpty(source)) {
            target = new LinkedHashMap<V, K>(source.size());
            for (Map.Entry<K, V> entry : source.entrySet()) {
                target.put(entry.getValue(), entry.getKey());
            }
        }
        return target;
    }
    /*map key 第一个字母小写*/
    public static Map<String, Object> keyLowerCaseFirstOne(Map<String, Object> source) {
        Map<String, Object> target = null;
        if (isNotEmpty(source)) {
            target = new LinkedHashMap<String, Object>(source.size());
            String key = null;
            for (Map.Entry<String, Object> entry : source.entrySet()) {
            	key = StringProcess.toLowerCaseFirstOne((String)entry.getKey());
                target.put(key, entry.getValue());
            }
        }
        return target;
    }
}
